<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>项目变更申请（老师）</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=10,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <link rel="stylesheet" type="text/css" href="/lib/layui/layui/css/layui.css"/>
    <script type="text/javascript" src="/js/news/jquery-1.9.1.js"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../js/jquery/jquery.cookie.js"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.ui.widget.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.iframe-transport.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.fileupload.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="/js/common/fileupload.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/layui.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/layui.all.js"></script>
</head>
<style>
    .mbox {
        padding: 8px
    }

    .item img {
        height: 40px;
    }

    .btn {
        height: 30px;
    }

    .btn button {
        float: right;
    }

    .information {
        background: #e8f4fc;
        height: 30px;
        line-height: 30px;
    }
    .layui-form-label{
        width: 77px;
    }
    .openFile input[type=file]{
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 18px;
        z-index: 99;
        opacity: 0;
    }
    .layui-table-cell .layui-form-checkbox[lay-skin=primary]{
            top: 5px;
        }

</style>
<body>
<div class="mbox">
    <div class="item">
        <img src="../img/yeji.png" alt="" style="margin: 0 5px 0 20px;"> <span
            style="font-size: 22px;display: inline-block;vertical-align: middle;">项目变更申请（老师）</span>
    </div>
    <hr class="layui-bg-blue">
    <div class="btn">
        <button type="button" class="layui-btn layui-btn-sm" style="background: #2b7fe0"><i
                class="layui-icon layui-icon-upload-drag" style="background: #2b7fe0"></i>导出Excel
        </button>
        <button type="button" class="layui-btn layui-btn-sm"  style="background: #2b7fe0;margin-right: 20px"><i
                class="layui-icon layui-icon-addition" id="addition" style="vertical-align: inherit"></i>自定义列表
        </button>
    </div>
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>
</body>
</html>
<script type="text/html" id="barDemo">
    {{# if(d.trStatus==3 || d.trStatus==6){ }}
    <a class="layui-btn  layui-btn-xs" lay-event="stop">终止</a>
    {{# }else{ }}
    <a class="layui-btn layui-btn-xs" style="cursor: not-allowed;background: #C1C1C1">终止</a>
    {{# } }}
    {{# if(d.trStatus==3 || d.trStatus==6){ }}
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="delay">延期</a>
    {{# }else{ }}
    <a class="layui-btn layui-btn-xs" style="cursor: not-allowed;background: #C1C1C1">延期</a>
    {{# } }}
    {{# if(d.trStatus==3 || d.trStatus==6){ }}
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">修改</a>
    {{# }else{ }}
    <a class="layui-btn layui-btn-xs" style="cursor: not-allowed;background: #C1C1C1">修改</a>
    {{# } }}
    {{# if(d.trStatus==3 || d.trStatus==6){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="changeHost">主持人变更</a>
    {{# }else{ }}
    <a class="layui-btn layui-btn-xs" style="cursor: not-allowed;background: #C1C1C1">主持人变更</a>
    {{# } }}
</script>
<script>
    layui.use(['table', 'form', 'laydate'], function () {
        var table = layui.table,
            form = layui.form,
            laydate = layui.laydate
        var tableIns=null
        function tableShow(){
            tableIns=table.render({
                elem: '#test'
                , url: '/process/selectChange'
                , cols: [[
                    {type: 'checkbox'}
                    , {field: 'topicName', title: '项目名称'}
                    , {field: 'planName', title: '申报计划名称'}
                    , {field: 'participantName', title: '项目成员'}
                    , {field: 'userName', title: '负责人'}
                    , {field: 'trStatus', title: '审批状态',templet:function (d) {
                            if(d.trStatus==1){
                                return '待审批'
                            }else if(d.trStatus==2){
                                return '已批准'
                            }else if(d.trStatus==3){
                                return '未批准'
                            }else{
                                return ''
                            }
                        }}
                    , {title: '操作', toolbar: '#barDemo'}
                ]]
                , page: true,
                where:{useFlag:true},
                parseData: function(res){ //res 即为原始返回的数据
                    return {
                        "code": 0, //解析接口状态
                        "count": res.totleNum, //解析数据长度
                        "data": res.obj //解析数据列表
                    };
                }
            });
        }
        tableShow()
        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            $.get('/process/getStatus1',{topicId:data.topicId,trType:2},function (res) {
                if(res==6 || res==3){
                    if (obj.event === 'stop') {
                        tool(1,data.topicId)
                    }else if(obj.event === 'edit'){
                        tool(3,data.topicId,data)
                    }else if(obj.event === 'delay'){
                        tool(2,data.topicId,data)
                    }else if(obj.event === 'changeHost'){
                        tool(4,data.topicId)
                    }
                }else{
                    layer.msg('该项目已提交审核，不可操作！',{icon:0});
                }
            })
        });
        function tool(type,topicId,data) {
            var title
            if(type=='1'){
                title='终止'
            }else if(type=='3'){
                title='修改'
            }else if(type=='2'){
                title='延期'
            }else if(type=='4'){
                title='主持人变更'
            }
            layer.open({
                type: 1,
                title: title,
                btn: ['确定', '取消'],
                shade: 0.5,
                maxmin:true,
                area: ['70%', '70%'],
                content: '<div class="layui-form">' +
                        //开始
                        '<div class="threeBtn">'+ //前三个按钮开始
                        '<div class="layui-row" style="margin-top:15px">' +
                        '<div class="layui-col-xs6">' +
                        '<div class="layui-form-item layui-form-text">\n' +
                    '    <label class="layui-form-label">'+function () {
                        if(type=='1'){
                            return '终止原因:'
                        }else if(type=='3'){
                            return '变更原因:'
                        }else if(type=='2'){
                            return '延期原因:'
                        }
                    }()+'</label>\n' +
                    '    <div class="layui-input-block">\n' +
                    '      <textarea name="trOther" class="layui-textarea"></textarea>\n' +
                    '    </div>\n' +
                    '  </div>'+
                        '</div>'+
                        '<div class="layui-col-xs6">' +
                        '  <div class="layui-form-item">\n' +
                    '    <label class="layui-form-label">'+function () {
                        if(type=='1'){
                            return '终止日期:'
                        }else if(type=='3'){
                            return '变更日期:'
                        }else if(type=='2'){
                            return '延期日期:'
                        }
                    }()+'</label>\n' +
                    '    <div class="layui-input-block">\n' +
                   ' <input type="text" class="layui-input" id="trTime" autocomplete="off" >'+
                    '    </div>\n' +
                    '  </div>'+
                    '</div>'+
                        '</div>'+
                        //开始
                    function () {
                        if(type=='3'){
                            return '<div class="layui-row">' +
                                '<div class="layui-col-xs12">' +
                                '<div class="layui-form-item layui-form-text">\n' +
                                '    <label class="layui-form-label">变更事项:</label>\n' +
                                '    <div class="layui-input-block">\n' +
                                    //
                                '    <label class="layui-form-label">负责人</label>\n' +
                                '    <div class="layui-input-block">\n' +
                                '  <textarea  type="text"  name="trOther2" id="trOther2" readonly  style="background:#e7e7e7;height: 45px;width: 370px;text-indent:1em;border-radius: 4px;"></textarea>\n' +
                                '<a href="javascript:;" style="color:#1E9FFF;margin-left:10px" chooseNum="1" class="userAdd">添加</a>\n' +
                                ' <a href="javascript:;" style="color:#1E9FFF;margin-left:5px" class="userDel">清空</a>\n'+
                                '    </div>\n' +
                                    //
                                '    <label class="layui-form-label">参与人员</label>\n' +
                                '    <div class="layui-input-block">\n' +
                                '  <textarea  type="text"  name="trOther3" id="trOther3" readonly  style="background:#e7e7e7;height: 45px;width: 370px;text-indent:1em;border-radius: 4px;" ></textarea>\n' +
                                '<a href="javascript:;" style="color:#1E9FFF;margin-left:10px" chooseNum="2" class="userAdd">添加</a>\n' +
                                ' <a href="javascript:;" style="color:#1E9FFF;margin-left:5px" class="userDel">清空</a>\n'+
                                '    </div>\n' +
                                    //
                                /*'    <label class="layui-form-label">课题类别</label>\n' +
                                '    <div class="layui-input-block" style="width: 58%">\n' +
                               '  <select name="trOther4" lay-verify="required">\n' +
                                '      </select>'+
                                '    </div>' +*/
                                    //
                                '    </div>\n' +
                                '  </div>'+
                                '</div>'+
                                '</div>'
                        }else{
                            return  ''
                        }
                    }()+
                    //开始
                    '<div class="layui-row">' +
                    '<div class="layui-col-xs12">' +
                    '<div class="layui-form-item layui-form-text">\n' +
                    '    <label class="layui-form-label">附件:</label>\n' +
                    '<div class="layui-input-block" style="padding-top: 9px">\n' +
                    '            <div id="fileAll"></div>\n' +
                    '            <a href="javascript:;" class="openFile" style="float: left;position:relative">\n' +
                    '                <img src="../img/mg11.png" alt="">\n' +
                    '                <span><fmt:message code="email.th.addfile"/></span>\n' +
                    '                <input type="file" multiple id="fileupload" data-url="/upload?module=fixAssets" name="file">\n' +
                    '            </a>\n' +
                    '        </div>'+
                    '  </div>'+
                    '</div>'+
                    '</div>'+

                    //开始
                    '<div class="layui-row" style="margin-top:15px">' +
                    '<div class="layui-col-xs12">' +
                    '<div class="layui-form-item layui-form-text">\n' +
                    '    <label class="layui-form-label">变更事由</label>\n' +
                    '    <div class="layui-input-block">\n' +
                    '      <textarea name="trOther8" class="layui-textarea"></textarea>\n' +
                    '    </div>\n' +
                    '  </div>'+
                    '</div>'+
                    '</div>'+

                     '</div>'+   //前三个按钮结束

                        //主持开始
                    '  <div class="oneBtn" style="margin-top:10px">'+
                      '  <div class="layui-form-item">\n' +
                    '    <label class="layui-form-label">第一主持人单位</label>\n' +
                    '    <div class="layui-input-block">\n' +
                    '      <input type="text" name="trOther9" autocomplete="off" class="layui-input">\n' +
                    '    </div>\n' +
                    '  </div>'+
                    '  <div class="layui-form-item">\n' +
                    '    <label class="layui-form-label">第二主持人单位</label>\n' +
                    '    <div class="layui-input-block">\n' +
                    '      <input type="text" name="trOther10" autocomplete="off" class="layui-input">\n' +
                    '    </div>\n' +
                    '  </div>'+
                    '  </div>'+
                        //主持结束

                    //备注
                    '<div style="width:87%;margin-left:12%">变更事由（1、申请延期、终止课题须写明原因，延期最长时间为一年。2、变更课题负责人须写明理由、新课题负责人的基本情况及是否有在研课题。3、变更课题单位须写明变更理由，由调出、调入单位签署意见。4、变更课题组重要成员须写明理由、变更成员的具体情况。5、研究内容原则上不作变更，确有特殊原因，须写明理由。6、各类变更申请需及时报区教育科研管理部门，研究同意后方可调整。）</div>'+


                    '</div>',
                success:function(){
                    laydate.render({
                        elem: '#trTime' //指定元素
                        ,trigger: 'click' //采用click弹出
                    });
                    fileuploadFn('#fileupload', $('#fileAll'));
                    if(type=='4'){
                        $('.oneBtn').show()
                        $('.threeBtn').hide()
                    }else{
                        $('.oneBtn').hide()
                        $('.threeBtn').show()
                    }
                    if(type=='3'){
                        $('#trOther2').val(data.userName || '')
                        $('#trOther2').attr('user_id',data.userId)
                        $('#trOther3').val(data.participantName || '')
                        $('#trOther3').attr('user_id',data.participant)
                      /*  $.ajax({
                            url:'/RpmDictonary/selectDictionaryByNo',
                            dataType: 'json',
                            type: 'get',
                            data:{
                                dictNo:'PROJECT_TYPE'
                            },
                            success: function (res) {
                                var obj = res.data
                                var str = '<option value="">请选择</option>'
                                for (var i = 0; i < obj.length; i++) {
                                    str += '<option value="' + obj[i].dictNo + '">' + obj[i].dictName + '</option>'
                                }
                                $('[name="trOther4"]').html(str);
                                $('[name="trOther4"]').val(data.topicType)
                                form.render('select');
                            }
                        })*/
                    }else if(type=='2'){
                        $('#trTime').val(data.completionTime)
                    }
                },
                yes:function (index, layero) {
                    var trOther=$('[name="trOther"]').val()
                    var trTime=$('#trTime').val() ? $('#trTime').val()+" 00:00:00"  : ''
                    var trOther5 = '';
                    var trOther6 = '';
                    for (var i = 0; i < $('#fileAll .dech').length; i++) {
                        trOther5 += $('#fileAll .dech').eq(i).find('input').val();
                        trOther6 += $('#fileAll a').eq(i).attr('name');
                    }
                    var trOther8=$('[name="trOther8"]').val()
                    var obj={
                        type:type,
                        topicId:topicId,
                        trOther:trOther,
                        trTime:trTime,
                        trOther5:trOther5,
                        trOther6:trOther6,
                        trOther8:trOther8,
                    }
                    if(type=='3'){
                        obj.trOther2=$('[name="trOther2"]').attr('user_id') ? $('[name="trOther2"]').attr('user_id').replace(/,$/,'') : ''
                        obj.trOther3=$('[name="trOther3"]').attr('user_id') ? $('[name="trOther3"]').attr('user_id').replace(/,$/,'') : ''
                        // obj.trOther4=$('[name="trOther4"]').val()
                    }
                    if(type=='4'){
                        obj={
                            trOther9:$('[name="trOther9"]').val(),
                            trOther10:$('[name="trOther10"]').val(),
                            type:type,
                            topicId:topicId,
                        }
                    }
                     $.post('/process/updateChange',obj,function (res) {
                         if(res.flag){
                             layer.msg('保存成功！',{icon:1});
                         }
                         layer.close(index)
                         tableIns.config.where._ = new Date().getTime();
                         tableIns.reload()
                     })
                }
            })
        }

        //选人控件添加
        $(document).on('click','.userAdd',function () {
            var chooseNum=$(this).attr('chooseNum')==1? '?0' : ''
            user_id=$(this).siblings('textarea').attr('id')
            $.popWindow("/common/selectUser"+chooseNum);
        })
        //选人控件删除
        $(document).on('click','.userDel',function () {
            var userId=$(this).siblings('textarea').attr('id')
            $('#'+userId).val('')
            $('#'+userId).attr('user_id','')
        })
        //删除附件
        $(document).on('click', '.deImgs', function () {
            var _this = this;
            var attUrl = $(this).parents('.dech').attr('deUrl');
            layer.confirm('确定删除该附件吗？', function (index) {
                $.ajax({
                    type: 'get',
                    url: '/delete?' + attUrl,
                    dataType: 'json',
                    success: function (res) {

                        if (res.flag == true) {
                            layer.msg('删除成功', {icon: 6, time: 1000});
                            $(_this).parent().remove();
                        } else {
                            layer.msg('删除失败', {icon: 2, time: 1000});
                        }
                    }
                })
            });
        });
    });
</script>